#include "gnlTexture.h"
/*
bool gnlTextureManager::verify_file(const char *file_name)
{
//FILE *fp;

//if((fp = fopen(file_name,"rb")) == 0) 
//	return false;

return true;
}

*/

bool gnlTextureManager::AddTexture(gnlTexture &textureData)
{
	GLuint image;
	ILboolean success;		
	ILuint texid;

	ilGenImages(1, &texid);
	
	ilBindImage(texid); 
	
	cout<<"file_name:"<<textureData.fileName.c_str()<<endl;
	
	success = ilLoadImage(textureData.fileName.c_str()); 

	if (success) {
		success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE); 
	     
		

	  glGenTextures(1, &image);

	  textureData.oglId = image; //Record OpenGL ID
	
	  glBindTexture(GL_TEXTURE_2D, image); 
	  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
	     
	  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
	     
	   // glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH),
		  //ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
		  //ilGetData()); 
	  gluBuild2DMipmaps( GL_TEXTURE_2D, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT),
					   ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData() );


	  }else
		return false;

	  //texture.push_back(textureData, id);

	  return true;
}
/*
UINT gnlTextureManager::getTexute( const gnlTexture &texture)
{
	/*for(int i=0;i<texture.size();i++)
		if(texture[i]->id == id)
			return texture[i]->tex;
	
	if(text
	if(textureId < texture.size())
		return //os valores de id gerados pelo opengl sao sempre positivos logo indica erro
}
*/